package org.liyufeng.project.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.liyufeng.project.model.PayrollDepartment;
import org.liyufeng.project.pojo.Token;
import org.liyufeng.project.pojo.WeixinDepartment;
import org.liyufeng.project.dao.PayrollDepartmentDao;
import org.liyufeng.project.dao.PayrollPersonalDao;
import org.liyufeng.project.util.CommonUtil;
import org.liyufeng.project.util.MySQLUtil;
import org.liyufeng.project.util.ParamesAPI;

public class PayrollDepartmentDaoImpl implements PayrollDepartmentDao{

private static Logger log = LoggerFactory.getLogger(PayrollDepartmentDaoImpl.class);
	
	public ArrayList<PayrollDepartment> getAll(String workshop){
		ArrayList<PayrollDepartment> list = new ArrayList<PayrollDepartment>();
		String sql = "select * from workshopsalary where workshop=? order by id desc limit 0,10";
		MySQLUtil mysqlUtil = new MySQLUtil();
		Connection conn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		log.info("workshop:{}",workshop);
		log.info("workshop:{}",sql);
		try {
			conn = mysqlUtil.getConn();
			ps = conn.prepareStatement(sql);
			ps.setString(1,workshop);
			rs = ps.executeQuery();			
			while (rs.next()) {
				
				PayrollDepartment PayrollDepartment = new PayrollDepartment();
				PayrollDepartment.setPostdate(rs.getString("postdate"));
				log.info("postdate:{}",PayrollDepartment.getPostdate());
				PayrollDepartment.setRcveweight(rs.getDouble("rcveweight"));
				PayrollDepartment.setRcvenum(rs.getInt("rcvenum"));
				PayrollDepartment.setNownum(rs.getInt("nownum"));
				PayrollDepartment.setTransnum(rs.getInt("transnum"));
				PayrollDepartment.setMonthweight(rs.getDouble("monthweight"));
				PayrollDepartment.setSalarytoday(rs.getDouble("salarytoday"));
				PayrollDepartment.setSalarymonth(rs.getDouble("salarymonth"));
				PayrollDepartment.setSalarycost(rs.getDouble("salarycost"));
				PayrollDepartment.setPromonthsalarycost(rs.getDouble("promonthsalarycost"));
				PayrollDepartment.setSalarycost2013(rs.getDouble("salarycost2013"));
				PayrollDepartment.setSalarycost2014(rs.getDouble("salarycost2014"));
				PayrollDepartment.setErrornote(rs.getString("errornote"));
									
				list.add(PayrollDepartment);
				
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			// 释放资源
			mysqlUtil.releaseResources(conn, ps, rs);
		}
		return list;
	}
	
	public PayrollDepartment getInfoByDate(String name,String date){
		//TODO：  按日期查询生产厂工资情况日报
		PayrollDepartment PayrollDepartment = new PayrollDepartment();
		
		return PayrollDepartment;
	}
	
}
